package com.by.ui.recyclerview;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.ArrayList;

/**
 * Created by admin on 2016/5/11.
 */
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.Holder> {
    private ArrayList<String> data = new ArrayList<>();
    private int page = 1;

    public MyAdapter() {

    }

    public void resetData() {
        page = 1;
        data.clear();
        for (int i = 0; i < 10; i++) {
            data.add("item_" + ((page - 1) * 10 + i + 1));
        }
        notifyDataSetChanged();
    }

    public void addData() {
        page++;
        for (int i = 0; i < 10; i++) {
            data.add("item_" + ((page - 1) * 10 + i + 1));
        }
        notifyDataSetChanged();
    }


    @Override
    public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
        TextView text = new TextView(parent.getContext());
        text.setMinimumHeight(80);
        text.setTextSize(22);
        return new Holder(text);
    }

    @Override
    public void onBindViewHolder(Holder holder, int position) {
        holder.text.setText(data.get(position));
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    public class Holder extends RecyclerView.ViewHolder {
        public TextView text;

        public Holder(View itemView) {
            super(itemView);
            text = (TextView) itemView;
        }
    }
}
